CPU 686
BITS 32

%define DATA_REG 0x60
%define EOI 0x20
%define PIC1_CMD 0x20
%define PIC2_CMD 0xA0


global _mouse_isr

global _byte1
global _byte2
global _byte3
global _completo
extern _mouse_queue
extern _putGQueue
global pacote



;-----------------------------------------------

section .data

_byte1 dd 0
_byte2 dd 0
_byte3 dd 0
_completo dd 0

nbyte dd 0
pacote db 0, 0, 0


;-----------------------------------------------

section .text

_mouse_isr:
	push eax
	push ecx

;-----------------------
	
	xor eax, eax
	xor ecx, ecx
	
	in al, DATA_REG
	mov ecx, dword[nbyte]
	
	cmp ecx, 2
	jz byte3
	cmp ecx, 1
	jz byte2
	
byte1:
	;mov dword[_byte1], eax
	mov byte[pacote], AL
	
	mov ecx, 1
	jmp fim

byte2:
	;mov dword[_byte2], eax
	mov byte[pacote+1], AL
	mov ecx, 2
	jmp fim
	
byte3:
	;mov dword[_byte3], eax
	mov byte[pacote+2], AL
	mov dword[_completo],1
	mov ecx, 0
	push pacote
	push dword[_mouse_queue]
	call _putGQueue
	add esp, 8

fim:
	mov dword[nbyte], ecx

;-----------------------
	
	mov al, EOI
	out PIC1_CMD, al
	out PIC2_CMD, al

	pop ecx
	pop eax
	iretd
END
